package cn.itlb.Demo;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestStudent {
	public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, SecurityException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		String student ="cn.itlb.Demo.Student";
		Class studentClass=Class.forName(student);
		Field field =studentClass.getDeclaredField("name");
		Method mothod=studentClass.getDeclaredMethod("study", String.class);
		Student stu=(Student) studentClass.newInstance();
		field.setAccessible(true);
		field.set(stu, "名字");
		String invokeResult=(String) mothod.invoke(stu, "名字2");
		System.out.println("动态方法调用返回:"+invokeResult);
				
		Method toStringMethod=studentClass.getDeclaredMethod("toString");
		
		invokeResult= (String) toStringMethod.invoke(stu);
		
		System.out.println(invokeResult);
		
	}
}
